home *** CD-ROM | disk | FTP | other *** search
- Path: columba.udac.uu.se!chaph!t94dwi
- From: t94dwi@chaph.tdb.uu.se (Daniel Widenfalk)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Return types and virtual methods.
- Date: 5 Feb 1996 11:40:47 GMT
- Organization: Uppsala University
- Message-ID: <4f4qbv$q18@columba.udac.uu.se>
- NNTP-Posting-Host: chaph.tdb.uu.se
- X-Newsreader: TIN [version 1.2 PL2]
-
- Hi all,
-
- I was trying to create a "set" class this weekend. I tried to do this:
-
- class Set {
- public:
- virtual ~Set();
-
- virtual Set & operator=(const Set &) = 0;
- virtual Set operator~() = 0;
- ...
- };
-
- class BitSet : public set {
- public:
- ~BitSet();
-
- BitSet & operator=(const BitSet &);
- BitSet operator~();
- ...
- };
-
- As you can see, I want to be able to handle several diffrent types
- of sets the same way. Now to the problem. This doesn't work. I get
- the error-message in my .cc file:
-
- BitSet operator~();
- BitSet cannot create instance of abstract object. (Or something like it)
-
- As I see it, I get two assignment operators. One for Set & and one for
- BitSet &. This make the Set & one undefined in BitSet and therefore
- BitSet is an abstract class. This makes the compiler barf when it gets
- to operator~, which
- 1) Tries to return an abstract class instance
- and
- 2) HAVE DIFFRENT return values.
-
- Now, my question is. How do I fix this? I want to be able to have several
- diffrent representations of sets, but I want them to look the same to the
- user.
-
- All help appreciated
- /Daniel Widenfalk
- t94dwi@student.tdb.uu.se
-